import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:industry_net/base/common/colors_util.dart';
import 'package:industry_net/base/common/img_util.dart';
import 'package:industry_net/base/common/size_fit.dart';
import 'package:industry_net/pages/tab_controller/controller.dart';

class TabPage extends GetView<TbController> {
  const TabPage({Key? key}) : super(key: key);

  Widget getIcon(String url) {
    return Image.asset(
      url.imgPathTabbar,
      width: 18.w,
      height: 18.w,
      fit: BoxFit.contain,
    );
  }

  @override
  Widget build(BuildContext context) {
    SizeFit.initialize();
    return Obx(
      () => Scaffold(
          body: IndexedStack(
            index: controller.state.currentIndex.value,
            children: controller.state.pages,
          ),
          bottomNavigationBar: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            selectedItemColor: ColorsUtil.theme,
            unselectedItemColor: ColorsUtil.subTitle,
            items: controller.state.items
                .map((e) => BottomNavigationBarItem(
                    label: e.title,
                    icon: getIcon(e.icon),
                    activeIcon: getIcon(e.activeIcon)))
                .toList(),
            currentIndex: controller.state.currentIndex.value,
            selectedFontSize: 12,
            unselectedFontSize: 12,
            onTap: (index) => controller.clickTab(index),
            backgroundColor: Colors.white,
          )),
    );
  }
}
// PageView(
//             physics: const NeverScrollableScrollPhysics(),
//             controller: controller.state.pageController,
//             children: controller.state.pages,
//           )